package com.yimils.core.goods.controller;

import com.yimils.core.common.dto.RspBase;
import com.yimils.core.goods.dto.VideoAddReq;
import com.yimils.core.goods.dto.VideoUpdateReq;
import com.yimils.core.goods.serivce.VideoService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Validated
public class VideoController {
    @Resource(name = "videoService")
    VideoService videoService;

    @PostMapping("/video/save")
    public RspBase saveVideo(@RequestBody VideoAddReq videoAddReq) {
        if (videoService.saveVideo(videoAddReq)) {
            return RspBase.OK("成功");
        }
        return RspBase.OK("失败");
    }


    @PutMapping("/video/update")
    public RspBase updateVideo(@RequestBody VideoUpdateReq videoUpdateReq) {
        if (videoService.updateVideo(videoUpdateReq)) {
            return RspBase.OK("成功");
        }
        return RspBase.OK("失败");
    }

    @DeleteMapping("/video/delete")
    public RspBase deleteVideo(List<Long> videoIds) {
        if (videoService.deleteVideo(videoIds)) {
            return RspBase.OK("成功");
        }
        return RspBase.OK("失败");
    }

    @GetMapping("/video/list")
    public RspBase listVideo() {
        RspBase rsp = RspBase.OK();
        rsp.put("data", videoService.listVideo());
        return rsp;
    }
}
